const {
	$U_GetItem,
	$U_UserInfo,
} = require('@utils/storage')
const {
	userMenu,
} = require('./config-menu')

module.exports = function() {
	let {
		mainComp,
	} = $['components-jq']
	let treeJQ = mainComp.treeJQ = $("#main-tree")
	let {
		user_role,
	} = $U_UserInfo()
	let data = userMenu.slice(2)
	if (user_role == 0 || user_role == 1)
		data = userMenu.concat()
	treeJQ.tree({
		data,
		onClick(node) {
			let {
				title,
				content,
			} = node.attributes
			let tabsJQ = mainComp.tabsJQ
			if (tabsJQ.tabs('exists', title)) {
				tabsJQ.tabs('select', title)
				return
			}
			if (typeof content == 'function') {
				content().then(html => {
					tabsJQ.tabs('add', {
						id: node.id,
						title: title,
						content: html,
						closable: true,
					})
				})
				return
			}
			tabsJQ.tabs('add', {
				id: node.id,
				title: title,
				content,
				closable: true,
			})
		},
	});
}